package com.naiterui.ehp.bs.payment.exception;

import javax.servlet.http.HttpServletRequest;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.binarywang.wxpay.exception.WxPayException;
import com.naiterui.ehp.bp.support.exception.BaseExceptionCodes;
import com.naiterui.ehp.bp.support.exception.BaseGlobalExceptionHandler;
import com.naiterui.ehp.bp.support.exception.ResponseVO;

import lombok.extern.slf4j.Slf4j;

/**
 * Spring MVC 全局异常， 统一异常格式
 *
 * @date 2017年09月09日
 * @since 1.0.0
 */
@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler extends BaseGlobalExceptionHandler {

    @ResponseBody
    @ExceptionHandler({WxPayException.class})
    public ResponseEntity<ResponseVO<Void>> handlerWxPayException(WxPayException e, HttpServletRequest request) {
        log.warn(e.getMessage());
        return this.getResponseEntity(request, e, BaseExceptionCodes.DATA_ERR, e.getMessage());
    }

}
